package com.stockz.scanner.screen;

import java.util.List;

import com.stockz.core.model.Bar;
import com.stockz.scanner.screen.configuration.GapScreenConfiguration;

public class GapScreen implements Screen<Object> {

	private final GapScreenConfiguration configuration 
			= new GapScreenConfiguration();
	@Override
	public Object getConfiguration() {
		return configuration;
	}

	@Override
	public int getMandatorySpan() {
		return 2;
	}

	
	@Override
	public boolean isMatch(List<Bar> barList) {
		if(barList != null && barList.size() > getMandatorySpan()){
			if(configuration.isUp()){
				return isUpGap(barList);
			}
			if(configuration.isDown()){
				return isDownGap(barList);
			}
		}
		return false;
	}
	
	
	public boolean isUpGap(List<Bar> barList){
		if(barList == null || barList.size() < 2) return false;
		return barList.get(0).getLow() > barList.get(1).getHigh();
	}
	
	public boolean isDownGap(List<Bar> barList){
		if(barList == null || barList.size() < 2) return false;
		return barList.get(0).getHigh() < barList.get(1).getLow();
	}

}
